Skip to content

Conversation

@m-sz
Copy link
Contributor

@m-sz m-sz commented Nov 10, 2025

Sell=buy token initiative

The ability to swap the same token pairs unlocks the potential for CoW to generally become a transaction relay service. This feature will allow users to execute pre- and post- interaction hooks as gasless transactions. The overall implementation has certain caveats:

  • Each settlement has to go through the settlement contract anyway, so the sell=buy token transactions would require users to send X amount of sell token and receive X - cost of the token back. It is not realistic, with the current state of GPv2 contract for the user to just send the cost amount and save on gas this way.
  • The solvers can really compete only by batching to save on gas costs
  • There is little incentive for this feature to be supported by other solvers, but having this support in baseline solver could generally be enough.

Lift restrictions on sell=buy token

Based the changes on https://github.com/cowprotocol/services/pull/2513/files, adapted to current state of the codebase.

  • Adds a command-line argument to the orderbook API to allow for same sell and buy token swaps. The SameBuyAndSell token error is not raised in that case
  • Adds e2e test case that checks if sell=buy quoting and orders are possible
  • Liquidity fetching happens only if the sell and buy tokens are different
  • Relaxes the invariant on Tokens struct to allow for same token pairs
  • Minor tweak to Justfile to allow for custom filtering and extra args to nextest

Based on input from @fhenneke:

  • Adds a short-circuit behavior for solver to return empty route in case sell=buy
  • Returns sell and buy assets directly when solving for empty route

@m-sz m-sz force-pushed the sell=buy branch 2 times, most recently from de09f52 to 858ac73 Compare November 12, 2025 15:54
@m-sz m-sz marked this pull request as ready for review November 12, 2025 15:55
@m-sz m-sz requested a review from a team as a code owner November 12, 2025 15:55
let pair = liquidity::TokenPair::try_new(self.tokens.sell(), self.tokens.buy())
.expect("sell != buy by construction");
iter::once(pair).collect()
fn liquidity_pairs(&self) -> Option<HashSet<liquidity::TokenPair>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to your changes, but it's super confusing that the method is called liquidity_pairs (plural) when it only returns one pair. 😵‍💫

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will figure out a more fitting name

.await
.unwrap()
.unwrap();
assert_eq!(quote_response.verified, order_quote.verified);
Copy link
Contributor

@fafk fafk Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these asserts for? 🤔 What does it signify that the order has a verified quote and has metadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions are also present on the normal place_order_with_quote and it makes sure that the quote and order's quote are verified.

@squadgazzz
Copy link
Contributor

I think this PR needs to be converted to a draft, since more changes are expected. @m-sz , is that correct?

@m-sz
Copy link
Contributor Author

m-sz commented Nov 13, 2025

Yep, had a bunch of 1:1s and will be adding feature flag to the whole change to control it in orderbook.

@m-sz m-sz marked this pull request as draft November 13, 2025 17:10
@m-sz m-sz marked this pull request as ready for review November 14, 2025 16:54
@m-sz
Copy link
Contributor Author

m-sz commented Nov 14, 2025

I have updated the PR with CLI argument to orderbook to allow for same sell and buy tokens.
Changes to baseline solver, to support those transactions will come in a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants